package com.lhhg.Action;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.lhhg.DTO.Team;
import com.lhhg.MySQL.TeamDAO;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class TeamAction extends ActionSupport implements ModelDriven<Team> {
	private static final long serialVersionUID = 1L;

	@Override
	public Team getModel() {
		// TODO Auto-generated method stub
		return null;
	}

	private Team team = new Team();
	private List<Team> teamList = new ArrayList<Team>();
	private TeamDAO teamDAO = new TeamDAO();
	private int soluong;

	public Team getTeam() {
		return team;
	}

	public void setTeam(Team team) {
		this.team = team;
	}

	public List<Team> getTeamList() {
		return teamList;
	}

	public void setTeamList(List<Team> teamList) {
		this.teamList = teamList;
	}

	public TeamDAO getTeamDAO() {
		return teamDAO;
	}

	public void setTeamDAO(TeamDAO teamDAO) {
		this.teamDAO = teamDAO;
	}

	public int getSoluong() {
		return soluong;
	}

	public void setSoluong(int soluong) {
		this.soluong = soluong;
	}

	@SuppressWarnings("unused")
	public String save() {
		HttpServletRequest request = (HttpServletRequest) ActionContext
				.getContext().get(ServletActionContext.HTTP_REQUEST);
		String tendoi = request.getParameter("tendoi");
		int diem = Integer.parseInt(request.getParameter("diem"));
		int hieuso = Integer.parseInt(request.getParameter("hieuso"));
		teamDAO.add(team);
		return SUCCESS;
	}

	@SuppressWarnings("static-access")
	public String list() {
		HttpServletRequest request = (HttpServletRequest) ActionContext
				.getContext().get(ServletActionContext.HTTP_REQUEST);
		teamList = teamDAO.getListTeam();
		request.setAttribute("teamList", teamList);
		return SUCCESS;
	}

	@SuppressWarnings("static-access")
	public String update() {
		HttpServletRequest request=(HttpServletRequest)ActionContext.getContext().get(
				ServletActionContext.HTTP_REQUEST);
		team=teamDAO.listTeamById(Integer.parseInt(request.getParameter("idteam")));
		return SUCCESS;
	}

}
